package com.xc.quickstart.common.bean;

import com.alibaba.fastjson.JSON;
import com.xc.quickstart.common.event.SampleApplicationEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;

@Configuration
@Slf4j
public class SampleEventListener implements ApplicationListener<SampleApplicationEvent> {


    @Async
    @Override
    public void onApplicationEvent(SampleApplicationEvent sampleApplicationEvent) {
        try {
            log.info("业务日志操作:{}", JSON.toJSONString(sampleApplicationEvent));
        } catch (Exception ex) {
            log.error("业务日志操作失败,异常:{}", ExceptionUtils.getStackTrace(ex));
        }
    }


}
